﻿#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Media.Imaging; 

#endregion

namespace Gonte.Wpf.Controls.ResourceManagers
{
    internal static class ImageManager
    {
        #region Methods

        internal static BitmapImage GetImage(string imageUri)
        {
            if (string.IsNullOrEmpty(imageUri))
            {
                return null;
            }

            if (_images.ContainsKey(imageUri))
            {
                return _images[imageUri];
            }

            BitmapImage image = new BitmapImage(new Uri(imageUri));

            lock (((ICollection)_images).SyncRoot)
            {
                _images.Add(imageUri, image);
            }

            return image;
        } 

        #endregion

        #region Properties

        internal static Dictionary<string, BitmapImage> Images
        {
            get { return ImageManager._images; }
        }  

        #endregion

        #region Fields

        private static readonly Dictionary<string, BitmapImage> _images = new Dictionary<string, BitmapImage>(); // Caches the image

        #endregion
    }
}
